package com.sh4.dao.impl;

import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.sh4.dao.UserRegisterDao;
import com.sh4.entity.User;

@Repository
public class UserRegisterDaoImpl extends BaseDaoImpl<User> implements UserRegisterDao {

	@Override
	public void saveUser(User user) {

		this.saveOrUpdate(user);
	}

	public Map<String, Object> getUserInfo(String userCode, String roleId) {
		String sql = "SELECT u.USER_CODE_ as userCode,u.EMil_ as emil , u.USER_NAME_ as userName,ur.ROLE_ID_ as roleId "
				+ " FROM user_role ur INNER JOIN user u ON(u.USER_CODE_ = ?) where ur.ROLE_ID_ = ? and ur.USER_CODE_ = u.USER_CODE_";

		return this.getUniqueResultBySql(sql, userCode, roleId);
	}

	@Override
	public User findUser(String userCode) {
		Criteria c = this.getSession().createCriteria(User.class);
		c.add(Restrictions.eq("userCode", userCode));
		return (User) c.uniqueResult();
	}

}
